#include "StdAfx.h"

#include "NetClient.h"
#include "tinyxml.h"

#include "tconfigsetting.h"
#include "ustringutils.h"
USING_LIBSPACE
namespace nettransport
{



	CNetClient::CNetClient(void)
	{
	}

	CNetClient::~CNetClient(void)
	{
	}

	bool CNetClient::Initialize(void* pParam)
	{
		try 
		{


			TConfigSetting setting ;
			setting.LoadConfig("ICE.CPPNetTransportServer.xml");

			m_port = setting["configuration"]["addr"].EleVal();
			m_addr = setting["configuration"]["port"].EleVal();


			m_ic = Ice::initialize();
			return true;
		}
		catch (const Ice::Exception & ex) 
		{
			std::cerr << ex << std::endl;
		}
		return false;
	}

	void CNetClient::UnInitialize()
	{
		if (m_ic) m_ic->destroy();
	}

	nettransport::IBasicCallPrx CNetClient::GetIBasicCallPrx(tstring id)
	{
		if(m_prxs.find(id) != m_prxs.end())
		{
			return m_prxs[id];
		}

		std::string objid = UStrConvUtils::ToStr(id);

		Ice::ObjectPrx base = m_ic->stringToProxy(  objid +  ":default -h " + m_addr + "  -p" + m_port);

		nettransport::IBasicCallPrx m_prx = nettransport::IBasicCallPrx::checkedCast(base);

		if (!m_prx) 
		{
			NULL;
		}
		m_prxs[id] = m_prx;


		return m_prx;
	}



}